<template>
  <section class="goodsList">
    <div class="list" v-for="(item,index) in goods" :key="index">
      <div class="img">
        <img :src="item.img" />
      </div>
      <div class="info">
        <div class="titleCount">
          <span class="title">{{item.title}}</span>
          <span class="count">{{item.count}}</span>
        </div>
        <div class="price">
          <span>{{item.price}}$</span>
          <span class="add" @click="addCart($event,item)">+</span>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import { mapActions } from "vuex";
export default {
  props: {
    goods: { type: Array, default: [] }
  },
  methods: {
    // ...mapActions(['addCart']),
    addCart(event, item) {
      this.$emit("cartanim", event.target);
      this.$store.commit("addCart", item);
    }
  }
};
</script>

<style scoped lang="scss">
.goodsList {
  .list {
    height: 80px;
    display: flex;
    border-bottom: 1px solid #ccc;
    .img {
      height: 80px;
      width: 120px;
      padding: 8px;
      box-sizing: border-box;
      img {
        height: 100%;
        width: 100%;
      }
    }
    .info {
      height: 80px;
      width: calc(100% - 120px);
      padding: 8px;
      box-sizing: border-box;
      .titleCount {
        height: 50%;
        display: flex;
        justify-content: space-between;
        .title {
          font-size: 16px;
          color: #333;
        }
        .count {
          font-size: 12px;
          color: #999;
        }
      }
      .price {
        height: 50%;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        color: #f56c6c;
        .add {
          width: 20px;
          height: 20px;
          border-radius: 50%;
          background: #f56c6c;
          color: #ffffff;
          display: flex;
          font-size: 20px;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
}
</style> 